package com.jwl.idc.http;

import android.content.Context;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by liangfan on 2015/12/30.
 * descript:针对业务逻辑的处理
 */
public class HttpAction {
    //有一个回调接口
    private HttpToViewInterface viewInterface = null;
    private Context mContext = null;


    public HttpAction(HttpToViewInterface viewInterface, Context mContext) {
        this.viewInterface = viewInterface;
        this.mContext = mContext;
    }

    //关闭相关的资源
    public void close() {
        if (viewInterface != null)
            viewInterface = null;
        if (mContext != null)
            mContext = null;
    }

    /**
     * 实现登录的操
     */
    public void login(String phoneNumber, String pwd) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("phoneNumber", phoneNumber);
        map.put("password",pwd);
        new Thread(new HttpActionExcute(HttpActionExcute.JWL_HTTP_LOGIN_KEY, map, new HttpActionBase(mContext, viewInterface))).start();
    }

    /**
     * 获取验证码
     */

    public void getSMS(String phoneNumber) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("phoneNumber", phoneNumber);
        new Thread(new HttpActionExcute(HttpActionExcute.JWL_HTTP_SENDSMS_KEY, map, new HttpActionBase(mContext, viewInterface))).start();
    }

    /**
     * 注册用户
     */
    public void registerUser(String phoneNumber, String pwd, String sms, String userName) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("phoneNumber", phoneNumber);
        map.put("password", pwd);
        map.put("smsCode", sms);
        map.put("userName", userName);
        new Thread(new HttpActionExcute(HttpActionExcute.JWL_HTTP_REGISTER_KEY, map, new HttpActionBase(mContext, viewInterface))).start();
    }

    /**
     * 获取锁列表
     */
    public void getDeviceList(String userId, String token) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userId", userId);
        map.put("token", token);
        new Thread(new HttpActionExcute(HttpActionExcute.JWL_HTTP_DEVICE_LIST_KEY, map, new HttpActionBase(mContext, viewInterface))).start();
    }
}
